package thread.api;

import org.apache.http.annotation.GuardedBy;

/**
 * Created mangcao with 2019/5/30 12:28
 * Description:
 */
public class HttpCore {


    public static void main(String[] args) {
        Student student = new Student("初始化");
        System.out.println(student.getName());

        Thread thread = new Thread(() -> {
            synchronized (student) {
                try {
                    Thread thread1 = Thread.currentThread();
                    System.out.println(thread1.getName());

                    Thread.sleep(5000);
                    System.out.println(student.getName()+10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        Thread thread1 = Thread.currentThread();
        System.out.println(thread1.getName());

        student.setName("後期");
        System.out.println(student.getName());

    }
}


class Student {


    @GuardedBy("this")
    private String name;

    public synchronized String getName() {
        return name;
    }

    public synchronized void setName(String name) {
        this.name = name;
    }

    public Student(String name) {
        this.name = name;
    }

    public Student() {
    }
}